function BXMediaLib(e){this.oConfig=e;window.MLItems={};this.arItemsCollList={};this.userSettings=this.oConfig.userSettings;this.arExt=this.oConfig.strExt.split(",")}BXMediaLib.prototype={Open:function(e){if(window.oBXMedialib&&oBXMedialib.bOpened)return;var t=this;this.sessid=this.oConfig.sessid;this.bOpened=true;this.width=this.userSettings.width;this.height=this.userSettings.height;this.zIndex=this.oConfig.zIndex||2050;this.Overlay=new BXOverlay({id:"bx_ml_trans_overlay"});this.bSubdialogOpened=false;this.arRedrawCollections={};this.Types=this.oConfig.Types;this.curType="";this.requestTypes=[];var i,l,o,s,n,a;for(i=0,l=this.Types.length;i<l;i++){s=[];o=this.Types[i].ext.split(",");for(n=0;n<o.length;n++){a=BX.util.trim(o[n]);if(a.length>0)s.push(a.toLowerCase())}this.Types[i].arExt=s;if(this.Types[i].system&&this.Types[i].code=="image")this.requestTypes.push(0);this.requestTypes.push(this.Types[i].id)}this.Request({action:"start",postData:{types:t.requestTypes},handler:function(e){if(!window.MLCollections)return false;if(e){t.arCollections=window.MLCollections;t.pWnd=document.body.appendChild(BX.create("DIV",{props:{id:"bxmedialib",className:"bxml-dialog"}}));var i=BX.GetWindowSize(),l=parseInt(i.scrollLeft+i.innerWidth/2-t.width/2),o=parseInt(i.scrollTop+i.innerHeight/2-t.height/2);if(!t.bReadOnly){var s=BX.create("DIV",{props:{className:"bxml-subdialog-cont"}});s.innerHTML=e.substring(e.indexOf("#ML_SUBDIALOGS_BEGIN#")+21,e.indexOf("#ML_SUBDIALOGS_END#"));Array.from(s.children).forEach(function(e){document.body.appendChild(e)})}t.pWnd.innerHTML=e.substring(e.indexOf("#ML_MAIN_DIALOG_BEGIN#")+22,e.indexOf("#ML_MAIN_DIALOG_END#"));t.Overlay.Create();BX.ZIndexManager.register(t.pWnd,{overlay:t.Overlay.pWnd});jsFloatDiv.Show(t.pWnd,l,o,5,false,false);t.Overlay.Show({clickCallback:{func:t.Close,obj:t}});t.OnDialogOpen()}}})},Close:function(){jsFloatDiv.Close(this.pWnd);BX.unbind(document,"keypress",window.MlOnKeypress);if(this.pWnd.parentNode){BX.ZIndexManager.unregister(this.pWnd);this.pWnd.parentNode.removeChild(this.pWnd)}this.Overlay.Remove();if(this.EditCollDialog)this.EditCollDialog.Overlay.Remove();if(this.EditItemDialog)this.EditItemDialog.Overlay.Remove();if(this.Confirm)this.Confirm.Overlay.Remove();oBXMedialib.bOpened=false},OnDialogOpen:function(){var e=this;this.pLeftCont=BX("ml_left_cont");this.pRightCont=BX("ml_right_cont");this.pFrameTbl=BX("ml_frame");this.pCollCont=BX("ml_coll_cont");this.pHeaderCont=BX("ml_head_cont");this.pListCont=BX("ml_list_cont");this.pButCont=BX("ml_but_cont");this.Search=new BXMLSearch(this);this.pInfo={pWnd:BX("ml_info_wnd"),name:BX("ml_info_name"),desc:BX("ml_info_desc"),keywords:BX("ml_info_keys"),collections:BX("ml_info_colls"),details:BX("ml_info_details")};this.pBread=BX("ml_breadcrumbs");this.pResizer=BX("bxml_resizer");this.pResizer.onmousedown=function(){e.ResizerMouseDown()};this.pResizer.ondrag=BX.False;this.pAddNewColl=BX("ml_add_collection");this.pAddNewItem=BX("ml_add_item");this.InitTypeSelector();this.BuildCollections();if(this.userSettings.coll_id>0)this.SelectCollection(this.userSettings.coll_id,true);if(!this.bReadOnly){this.pAddNewColl.onclick=function(t){e.OpenEditCollDialog({bGetSelCol:true});return BX.PreventDefault(t)};this.pAddNewColl.style.display=this.bCommonEdit?"inline":"none";this.pAddNewItem.onclick=function(t){e.OpenEditItemDialog({bGetSelCol:true});return BX.PreventDefault(t)};this.pAddNewItem.style.display=this.bCommonItemEdit?"inline":"none"}else{this.pAddNewColl.style.display="none";this.pAddNewItem.style.display="none"}BX("medialib_but_cancel").onclick=BX("bxml_close").onclick=function(){e.Close()};this.pButSave=BX("medialib_but_save");this.pButSave.onclick=function(){e.Submit()};if(this.bNoCollections){BX.addClass(this.pLeftCont,"ml-no-colls-sect");this.pAddNewItem.style.display="none"}window.MlOnKeypress=function(t){if(!t)t=window.event;if(t&&t.keyCode==27&&!e.bSubdialogOpened)e.Close()};BX.bind(document,"keypress",window.MlOnKeypress);this.FillInfoPanel(false);setTimeout(function(){e.Resize(e.width,e.height)},50)},Submit:function(){if(!this.SelectedItemId||!this.oCurItems[this.SelectedItemId]||!this.oConfig.resType||!this.oConfig.arResultDest)return false;var e=this.oCurItems[this.SelectedItemId].oItem,t=this.oConfig.resType,i=this.oConfig.arResultDest;if(t=="FUNCTION"&&typeof window[i.FUNCTION_NAME]=="function"){window[i.FUNCTION_NAME]({src:e.path,name:bxspcharsback(e.name),description:bxspcharsback(e.desc),width:e.width,height:e.height,file_size:e.file_size,type:"image"})}else if(t=="FORM"&&document.forms[i.FORM_NAME]&&document.forms[i.FORM_NAME][i.FORM_ELEMENT_NAME]){document.forms[i.FORM_NAME][i.FORM_ELEMENT_NAME].value=e.path;BX.fireEvent(document.forms[i.FORM_NAME][i.FORM_ELEMENT_NAME],"change")}else if(t=="ID"&&BX(i.ELEMENT_ID)){BX(i.ELEMENT_ID).value=e.path;BX.fireEvent(BX(i.ELEMENT_ID),"change");if(this.oConfig.description_id.length>0&&BX(this.oConfig.description_id))BX(this.oConfig.description_id).value=e.name}else{alert(ML_MESS.BadSubmit)}this.Close()},BuildCollections:function(){this.oCollections={};this.arCollectionsTree=[];this.bCommonEdit=!!this.oConfig.rootAccess.edit||false;this.bCommonItemEdit=!!this.oConfig.rootAccess.edit_item||false;this.bNoCollections=true;var e=[],t,i=0,l,o=this.arCollections.length;for(l=0;l<o;l++){if(!this.BuildCollection(this.arCollections[l],l))e.push([this.arCollections[l],l])}while(e.length>0&&i<50){o=e.length;t=[];for(l=0;l<o;l++){if(!this.BuildCollection(e[l][0],e[l][1]))t.push(e[l])}e=t;i++}this.bReadOnly=!this.bCommonEdit&&!this.bCommonItemEdit;if(this.bNoCollections){BX.addClass(this.pLeftCont,"ml-no-colls-sect");this.pAddNewItem.style.display="none"}},BuildCollection:function(e,t){if(typeof e!="object"||!this.CheckMLType(e.type))return true;if(this.bNoCollections){this.bNoCollections=false;BX.removeClass(this.pLeftCont,"ml-no-colls-sect");this.pAddNewItem.style.display="inline"}var i,l,o=this,s;e.parent=parseInt(e.parent);if(!e.parent){i=this.pCollCont;l=0;s=this.arCollectionsTree}else if(this.oCollections[e.parent]){i=this.oCollections[e.parent].pChildCont;l=this.oCollections[e.parent].level+1;this.oCollections[e.parent].childCount++;if(this.oCollections[e.parent].childCount==1)this.oCollections[e.parent].icon.className="ml-col-icon-closed";s=this._ReqFindChildCol(this.arCollectionsTree,e.parent)}else return false;s.push({id:e.id,child:[]});this.arRedrawCollections[this.curType.id]=true;if(i){var n=this.UserCan(e,"del"),a=this.UserCan(e,"edit"),d=BX.create("DIV",{props:{id:"ml_coll_title_"+e.id}}),r=d.appendChild(BX.create("IMG",{props:{src:"/bitrix/images/1.gif",className:"ml-col-icon"}})),h=d.appendChild(BX.create("SPAN",{props:{title:bxspcharsback(e.desc||e.name)},text:e.name})),c=BX.create("DIV",{props:{className:"ml-coll-child-cont"}});if(n){var p=d.appendChild(BX.create("IMG",{props:{src:"/bitrix/images/1.gif",className:"ml-col-del",title:ML_MESS.DelCollection}}));p.onclick=function(e){o.DelCollection(this.parentNode.id.substr("ml_coll_title_".length));return BX.PreventDefault(e||window.event)}}if(a){var m=d.appendChild(BX.create("IMG",{props:{src:"/bitrix/images/1.gif",className:"ml-col-edit",title:ML_MESS.EditCollection}}));m.onclick=function(e){var t=this.parentNode.id.substr("ml_coll_title_".length);o.OpenEditCollDialog({id:t});return BX.PreventDefault(e||window.event)};this.bCommonEdit=true}if(!this.bCommonItemEdit&&this.UserCan(e,"new_item"))this.bCommonItemEdit=true;if(n||a){d.onmouseover=function(){BX.addClass(this,"mlcollt-over")};d.onmouseout=function(){BX.removeClass(this,"mlcollt-over")}}o._SetColTitleLevel(d,l);d.title=bxspcharsback(e.desc||e.name);d.onclick=function(){o.SelectCollection(this.id.substr("ml_coll_title_".length))};r.onclick=function(e){var t=this.parentNode.id.substr("ml_coll_title_".length);o.OpenCollection(t);return BX.PreventDefault(e||window.event)};i.appendChild(d);i.appendChild(c);this.oCollections[e.id]={ind:t,pTitle:d,pChildCont:c,icon:r,level:l,childCount:0,bOpened:false};return true}},ReNewCollectionTree:function(){this.arRedrawCollections[this.curType.id]=true;this.arCollectionsTree=[];var e=[],t,i=0,l,o=this.arCollections.length;for(l=0;l<o;l++){if(typeof this.arCollections[l]!="object"||!this.CheckMLType(this.arCollections[l].type))continue;if(!this.ReNewCol4Tree(this.arCollections[l]))e.push(this.arCollections[l])}while(e.length>0&&i<50){o=e.length;t=[];for(l=0;l<o;l++){if(!this.ReNewCol4Tree(e[l]))t.push(e[l])}e=t;i++}},ReNewCol4Tree:function(e){var t=parseInt(e.parent),i;if(!t)i=this.arCollectionsTree;else if(this.oCollections[t])i=this._ReqFindChildCol(this.arCollectionsTree,t);if(!i)return false;i.push({id:e.id,child:[]});return true},SelectCollection:function(e,t){var i=this.oCollections[e];if(!i||this.SelectedColId==e)return;this.DeSelectCollection(false);this.SelectedColId=e;BX.addClass(i.pTitle,"mlcollt-active");var l=this.GetCollsCrumbs(e);this.BuildCrumbs(l);if(t){var o,s=l.length;for(o=1;o<s;o++){if(!this.oCollections[l[o].id].bOpened)this.OpenCollection(l[o].id)}}this.userSettings.coll_id=e;this.ShowItems(e);this.SelectItem();this.SaveSettings()},DeSelectCollection:function(e){if(this.SelectedColId&&this.oCollections[this.SelectedColId])BX.removeClass(this.oCollections[this.SelectedColId].pTitle,"mlcollt-active");if(e!==false)this.BuildCrumbs([])},UserCan:function(e,t){var i;if(typeof e!=="object"){if(e===0){i=this.oConfig.rootAccess}else{e=this.GetCollection(e);if(typeof e!=="object")return false;i=e.access}}else{i=e.access}return i&&i[t]==="1"},GetCollsCrumbs:function(e){var t=[],i;while(e){i=this.GetCollection(e);if(i){t.push(i);e=i.parent}else e=false}return t},BuildCrumbs:function(e){while(this.pBread.childNodes.length>0)this.pBread.removeChild(this.pBread.firstChild);var t=this,i,l,o=e.length;for(l=o-1;l>=0;l--){i=e[l];if(!i||typeof i!="object")continue;pCr=this.pBread.appendChild(BX.create("DIV",{props:{className:"ml-crumb",id:"ml_crumb_"+i.id,title:i.desc},text:i.name}));if(l>0){this.pBread.appendChild(BX.create("DIV",{props:{className:"ml-crumb-sep"}})).appendChild(document.createTextNode(" "));pCr.onclick=function(){t.SelectCollection(this.id.substr("ml_crumb_".length))}}else{pCr.style.cursor="default"}}return e},GetCollection:function(e){if(this.oCollections[e])return this.arCollections[this.oCollections[e].ind];var t,i=this.arCollections.length;for(t=0;t<i;t++)if(this.arCollections[t].id==e)return this.arCollections[t];return false},_ReqFindChildCol:function(e,t){var i,l=e.length,o=false;for(i=0;i<l;i++){if(e[i].id==t){o=e[i].child;break}else if(e[i].child.length>0){o=this._ReqFindChildCol(e[i].child,t);if(o)break}}return o},_ReqBuildCollSelect:function(e,t,i,l){if(!i)i=0;var o,s=t.length,n=e.options.length,a,d;if(l==true){var r=1;while(e.options[r])e.options[r]=null}for(o=0;o<s;o++){col=this.GetCollection(t[o].id);if(col){d="";for(a=0;a<i;a++)d+=" . ";d+=bxspcharsback(col.name);opt=new Option(d,t[o].id);opt.title=bxspcharsback(col.name);e.options.add(opt);if(t[o].child.length>0)this._ReqBuildCollSelect(e,t[o].child,i+1)}}},OpenCollection:function(e){var t=this.oCollections[e];if(t.childCount>0){if(!t.bOpened){t.pChildCont.style.display="block";t.icon.className="ml-col-icon ml-col-icon-opened"}else{t.pChildCont.style.display="none";t.icon.className="ml-col-icon ml-col-icon-closed"}t.bOpened=!t.bOpened}},DelCollection:function(e){if(e>0&&confirm(ML_MESS.DelCollectionConf)){var t=[];if(this.oCollections[e].childCount>0){var i=this.oCollections[e].pChildCont.getElementsByTagName("DIV"),l,o=i.length,s;for(l=0;l<o;l++){if(i[l].id.substr(0,14)=="ml_coll_title_"){s=parseInt(i[l].id.substr(14));if(s>0)t.push(s)}}}var n=this;this.Request({action:"del_collection",postData:{id:e,child_cols:t},handler:function(){if(window.bx_req_res)n.CSDelCollection(e,t)}})}},_IncreaseCollChild:function(e,t){var i=this.oCollections[e];if(i){if(t!==-1){i.childCount++;if(i.childCount>0){i.icon.className="ml-col-icon "+(i.bOpened?"ml-col-icon-opened":"ml-col-icon-closed");if(i.bOpened)i.pChildCont.style.display="block"}}else{i.childCount--;if(i.childCount<=0){i.icon.className="ml-col-icon";i.pChildCont.style.display="none"}}}},_SetColTitleLevel:function(e,t){e.className="ml-coll-title mlcolllevel-"+(t>3?3:t);e.childNodes[0].style.marginLeft=3+t*8+"px";if(t>=3)e.childNodes[1].className="ml-smaller-title"},SaveCollection:function(){var e=this.EditCollDialog,t=this,i={name:encodeURIComponent(e.pName.value),desc:encodeURIComponent(e.pDesc.value),keywords:encodeURIComponent(e.pKeys.value),parent:e.pParent.value,type:e.typeId};if(e.pName.value==""){alert(ML_MESS.ColNameError);e.pName.focus();return false}if(!e.bNew)i.id=e.oCol.id;this.Request({action:"edit_collection",postData:i,handler:function(){if(window.bx_req_res!==false){t.CloseEditCollDialog();var l={id:window.bx_req_res.id,name:e.pName.value,desc:e.pDesc.value,date:"",keywords:e.pKeys.value,parent:i.parent,access:window.bx_req_res.access,type:e.typeId};if(e.bNew){t.bNoCollections=true;t.arCollections.push(l);t.BuildCollection(l,t.arCollections.length-1)}else{var o=t.oCollections[l.id].pTitle,s=t.oCollections[l.id].pChildCont,n=t.arCollections[t.oCollections[l.id].ind].parent,a=l.parent||0;if(t.arCollections[t.oCollections[l.id].ind].parent!=a){t._IncreaseCollChild(n,-1);t._IncreaseCollChild(a);var d=a==0?t.pCollCont:t.oCollections[a].pChildCont;d.appendChild(o);d.appendChild(s);var r=a==0?0:t.oCollections[a].level+1;t.oCollections[l.id].level=r;t._SetColTitleLevel(o,r)}t.arCollections[t.oCollections[l.id].ind]=l;o.childNodes[1].innerHTML=BX.util.htmlspecialchars(l.name);o.title=l.desc||l.name}t.ReNewCollectionTree();t.SelectCollection(l.id)}else{alert("error")}}})},OpenEditCollDialog:function(e){if(!e)e={};if(!this.EditCollDialog)this.CreateEditCollDialog();this.EditCollDialog.bNew=!e.id;var t=this.EditCollDialog,i=BX.GetWindowSize(),l=parseInt(i.scrollLeft+i.innerWidth/2-t.width/2),o=parseInt(i.scrollTop+i.innerHeight/2-t.height/2);if(this.arRedrawCollections[this.curType.id]){this._ReqBuildCollSelect(t.pParent,this.arCollectionsTree,0,true);this.arRedrawCollections[this.curType.id]=false}t.pWnd.style.display="block";this.bSubdialogOpened=true;this.EditCollDialog.bFocusKeywords=false;if(!t.bNew){var s=this.GetCollection(e.id);t.pName.value=bxspcharsback(s.name);t.pDesc.value=bxspcharsback(s.desc);t.pKeys.value=bxspcharsback(s.keywords);t.pParent.value=s.parent||0;this.EditCollDialog.oCol=s}else{t.pName.value="";t.pDesc.value="";t.pKeys.value="";t.pParent.value=0;this._SetFirstAvailableCol();if(!e.parentCol&&e.bGetSelCol&&this.SelectedColId&&this.oCollections[this.SelectedColId])e.parentCol=this.SelectedColId;if(e.parentCol>0&&this.UserCan(e.parentCol,"new_col"))t.pParent.value=e.parentCol;var s=this.GetCollection(e.parentCol);if(s&&s.keywords)t.pKeys.value=s.keywords}t.typeId=this.curType.id||"";t.pName.onchange();jsFloatDiv.Show(this.EditCollDialog.pWnd,l,o,5,false,false);t.Overlay.Show();BX.bind(document,"keypress",window.MlEdColOnKeypress)},CreateEditCollDialog:function(e){var t=this,i={width:360,height:230,pWnd:BX("mlsd_coll"),pTitle:BX("mlsd_coll_title"),pName:BX("mlsd_coll_name"),pDesc:BX("mlsd_coll_desc"),pKeys:BX("mlsd_coll_keywords"),pParent:BX("mlsd_coll_parent"),Overlay:new BXOverlay({id:"bxml_ed_col_overlay"})};i.pName.onkeydown=i.pName.onchange=function(){setTimeout(function(){var e=t.EditCollDialog,i=bxhtmlspecialchars(e.pName.value),l=e.bNew?ML_MESS.NewCollection:ML_MESS.Collection;e.pTitle.title=l+(i.length>0?": "+e.pName.value:"");e.pTitle.innerHTML=l+(i.length>0?": "+i:"")},20)};i.pKeys.onchange=i.pKeys.onblur=function(){t.EditCollDialog.bFocusKeywords=true};i.pParent.onchange=function(){if(!t.EditCollDialog.bNew&&this.value==t.EditCollDialog.oCol.parent)return true;if(t.EditCollDialog.bNew&&!t.UserCan(parseInt(this.value),"new_col")||!t.EditCollDialog.bNew&&!t.UserCan(parseInt(this.value),"edit")){t._SetFirstAvailableCol();return alert(ML_MESS.CollAccessDenied3)}if(t.EditCollDialog.oCol){var e=t._ReqFindChildCol(t.arCollectionsTree,t.EditCollDialog.oCol.id);if(!e||t._ReqFindChildCol(e,this.value)){alert(ML_MESS.ColLocEr2);this.value=t.EditCollDialog.oCol.parent||0;return true}}if(!t.EditCollDialog.bNew&&t.EditCollDialog.oCol.id==this.value){alert(ML_MESS.ColLocEr);this.value=t.EditCollDialog.oCol.parent||0}if(t.EditCollDialog.bNew&&!t.EditCollDialog.bFocusKeywords&&this.value>0){var l=t.GetCollection(this.value);if(l&&l.keywords)i.pKeys.value=l.keywords}};BX("mlsd_coll_save").onclick=function(){t.SaveCollection()};BX("mlsd_coll_cancel").onclick=function(){t.CloseEditCollDialog()};BX("mlsd_coll_close").onclick=function(){t.CloseEditCollDialog()};this.arRedrawCollections[this.curType.id]=true;window.MlEdColOnKeypress=function(e){if(!e)e=window.event;if(e&&e.keyCode==27)t.CloseEditCollDialog()};i.pWnd.style.width=i.width+"px";i.pWnd.style.height="auto";i.pWnd.style.minHeight="10px";this.EditCollDialog=i;i.Overlay.Create();BX.ZIndexManager.register(i.pWnd,{overlay:i.Overlay.pWnd})},CloseEditCollDialog:function(){this.EditCollDialog.pWnd.style.display="none";jsFloatDiv.Close(this.EditCollDialog.pWnd);this.EditCollDialog.Overlay.Hide();this.bSubdialogOpened=false;BX.unbind(document,"keypress",window.MlEdColOnKeypress)},_SetFirstAvailableCol:function(e){var t=this.EditCollDialog,e=t.bNew?"new_col":"edit",i,l,o,s=t.pParent.options.length;if(!t.bNew&&t.oCol.parent)t.pParent.value=t.oCol.parent;if(this.oConfig.rootAccess[e])t.pParent.value=0;else{for(o=0;o<s;o++){i=t.pParent.options[o].value;l=this.GetCollection(i);if(l&&l.access&&l.access[e]){t.pParent.value=i;return}}}},ShowItems:function(e){var t=this;if(this.currentIdShowed==e)return;var i=this.GetCollection(e),l={edit:this.UserCan(i,"edit_item"),del:this.UserCan(i,"del_item")};if(typeof MLItems[e]!=="object"){this.Request({action:"get_items",postData:{col_id:e},handler:function(){if(!window.MLItems[e])return false;t.DisplayItems(MLItems[e],l);this.currentIdShowed=e}})}else{this.DisplayItems(MLItems[e],l);this.currentIdShowed=e}},DisplayItems:function(e,t){while(this.pListCont.childNodes[1])this.pListCont.removeChild(this.pListCont.lastChild);this.oCurItems={};this.pListCont.firstChild.style.display=e&&e.length?"none":"block";if(e&&e.length){var i,l=e.length;for(i=0;i<l;i++)this.DisplayItem(e[i],t)}},DisplayItem:function(e,t,i){if(!e||typeof e!="object")return;var l=this,o=this.oConfig.thumbWidth,s=this.oConfig.thumbHeight,n=BX.create("DIV",{props:{id:"ml_item_"+e.id,className:"ml-item-cont",title:bxspcharsback(e.name)},style:{width:o+15+"px",height:s+35+"px"}}),a=n.appendChild(BX.create("IMG",{props:{src:e.thumb_path||"/bitrix/images/1.gif",className:"ml-item-thumb"}})),d=n.appendChild(BX.create("DIV",{props:{className:"ml-item-title"},style:{width:o+8+"px"}}));var r=e.thumb_path||e.path;if(e.type=="image"&&r)a.style.backgroundImage="url('"+r+"')";if(!e.thumb_path||!e.width||!e.height){BX.addClass(a,"ml-item-no-thumb");e.height=100}if(s>e.height){var h=Math.round((s-e.height)/2);if(h>0){a.style.marginTop=h+"px";a.style.marginBottom=h+"px"}}d.appendChild(document.createTextNode(bxspcharsback(e.name)));var c=n.appendChild(BX.create("DIV",{props:{className:"ml-item-but-cont"}}));var p=c.appendChild(BX.create("IMG",{props:{src:"/bitrix/images/1.gif",className:"ml-item-view",title:ML_MESS.ViewItem}}));p.onclick=function(e){var o=this.parentNode.parentNode.id.substr("ml_item_".length);l.GetItemCollList(o,"OpenViewItDialog",{id:o,Access:t,bSearch:i});return BX.PreventDefault(e||window.event)};if(t.edit||t.del){if(t.edit){var m=c.appendChild(BX.create("IMG",{props:{src:"/bitrix/images/1.gif",className:"ml-item-edit",title:ML_MESS.EditItem}}));m.onclick=function(e){var t=this.parentNode.parentNode.id.substr("ml_item_".length);l.GetItemCollList(t,"OpenEditItemDialog",{id:t});return BX.PreventDefault(e||window.event)}}if(t.del){var f=c.appendChild(BX.create("IMG",{props:{src:"/bitrix/images/1.gif",className:"ml-item-del",title:ML_MESS.DelItem}}));f.onclick=function(e){var t=this.parentNode.parentNode.id.substr("ml_item_".length);l.GetItemCollList(t,"DelItem",{id:t});return BX.PreventDefault(e||window.event)}}n.onmouseover=function(){BX.addClass(this,"ml-item-cont-over")};n.onmouseout=function(){BX.removeClass(this,"ml-item-cont-over")}}n.onclick=function(e){l.SelectItem(this.id.substr("ml_item_".length))};n.ondblclick=function(e){l.Submit()};this.oCurItems[e.id]={oItem:e,pWnd:n};this.pListCont.appendChild(n)},OpenViewItDialog:function(e){if(!this.ViewItDialog)this.CreateViewItDialog(e);var t=this.ViewItDialog;var i=this.oCurItems[e.id].oItem;this.bSubdialogOpened=true;if(!i)return;t.oItem=i;t.colId=e.colId;t.pDel.style.display=e.Access.del?"inline":"none";t.pEdit.style.display=e.Access.edit?"inline":"none";t.pWnd.style.display="block";t.pWnd.style.visibility="hidden";t.bOpened=true;t.Overlay.Show();this.SetItemInfo(i)},CreateViewItDialog:function(e){var t=this,i={width:100,height:100,pWnd:BX("mlsd_view_item"),pItemCont:BX("mlsd_item_cont"),pInfoCont:BX("mlsd_info_cont"),pName:BX("mlvi_info_name"),pCols:BX("mlvi_info_colls"),pKeys:BX("mlvi_info_keys"),pDesc:BX("mlvi_info_desc"),pDetails:BX("mlvi_info_details"),pDel:BX("mlsd_viewit_del"),pEdit:BX("mlsd_viewit_edit"),pLink:BX("mlvi_info_link"),pCopyLink:BX("mlvi_info_copy_link"),pCopyInput:BX("mlvi_info_copy_input"),pExt:BX("mlvi_info_ext"),Overlay:new BXOverlay({id:"bxml_viewit_overlay"})};BX("mlsd_viewit_cancel").onclick=function(){t.CloseViewItDialog()};BX("mlsd_viewit_close").onclick=function(){t.CloseViewItDialog()};i.pDel.onclick=function(e){t.DelItem({id:t.ViewItDialog.oItem.id,colId:t.ViewItDialog.colId})};i.pEdit.onclick=function(i){t.CloseViewItDialog();t.OpenEditItemDialog({id:t.ViewItDialog.oItem.id,colId:t.ViewItDialog.colId,bSearch:e.bSearch})};window.MlViewItOnKeypress=function(e){if(!e)e=window.event;if(e&&e.keyCode==27)t.CloseViewItDialog()};this.ViewItDialog=i;i.Overlay.Create();BX.ZIndexManager.register(i.pWnd,{overlay:i.Overlay.pWnd})},CloseViewItDialog:function(){this.ViewItDialog.bOpened=false;this.bSubdialogOpened=false;this.ViewItDialog.pWnd.style.display="none";this.ViewItDialog.pCopyInput.style.display="none";jsFloatDiv.Close(this.ViewItDialog.pWnd);this.ViewItDialog.Overlay.Hide();BX.unbind(document,"keypress",window.MlViewItOnKeypress)},SetItemInfo:function(e){var t=this,i=this.ViewItDialog,l=this.arItemsCollList[e.id],o="",s,n=l.length,a,d;i.pName.innerHTML=BX.util.htmlspecialchars(e.name);i.pName.title=e.name;i.pLink.href=e.path;i.pCopyLink.onclick=function(){i.pCopyInput.value=e.path.substr(0,1)!=="/"?e.path:window.location.protocol+"//"+window.location.host+e.path;i.pCopyInput.style.display="block";i.pCopyInput.select()};if(e.keywords.length>0){i.pKeys.parentNode.className="small-grey";i.pKeys.innerHTML=BX.util.htmlspecialchars(e.keywords);i.pKeys.title=bxspcharsback(e.keywords)}else{i.pKeys.parentNode.className="ml-info-keys-h"}if(e.desc.length>0){i.pDesc.innerHTML=BX.util.htmlspecialchars(e.desc.replace(/\n/g,"<br />"));i.pDesc.parentNode.className="small-grey"}else{i.pDesc.parentNode.className="ml-info-desc-h"}for(var r=i.pCols.childNodes.length-1;r>0;r--)if(i.pCols.childNodes[r].nodeName.toLowerCase()!="span")i.pCols.removeChild(i.pCols.childNodes[r]);for(s=0;s<n;s++)o+=BX.util.htmlspecialcharsback(this.GetCollection(l[s]).name+(s!=n-1?", ":""));i.pCols.appendChild(document.createTextNode(o));var h=ML_MESS.FileExt+": "+e.path.substr(e.path.lastIndexOf(".")+1);h+="<br />"+ML_MESS.DateModified+": "+e.date_mod;if(e.file_size)h+="<br />"+ML_MESS.FileSize+": "+e.file_size;if(e.width&&e.height)h+="<br />"+ML_MESS.ImageSize+": "+e.width+" x "+e.height+" px";i.pDetails.innerHTML=h;this.SetItemHTML(e)},SetItemHTML:function(e){var t=this.ViewItDialog;this.Request({action:"get_item_view",postData:{id:e.id},handler:function(){var e=window.bx_req_res.html;var i=[],l,o,s,n;while((l=e.indexOf("<"+"script>"))!=-1){var o=e.indexOf("</"+"script>",l);if(o==-1)break;i[i.length]=e.substr(l+8,o-l-8);e=e.substr(0,l)+e.substr(o+9)}for(var s=0,n=i.length;s<n;s++)if(i[s]!="")jsUtils.EvalGlobal(i[s]);t.pItemCont.innerHTML=e;var a=parseInt(window.bx_req_res.width)||100,d=parseInt(window.bx_req_res.height)||50;if(a<100)a=100;if(t.pDesc&&parseInt(t.pDesc.offsetHeight)>d-200){t.pDesc.style.height=(d>=400?d-200:200)+"px";t.pDesc.style.overflow="auto"}var r=parseInt(t.pInfoCont.offsetHeight)||0,h=80+(d>r?d:r),c=270+a,p=BX.GetWindowSize(),m=parseInt(p.scrollLeft+p.innerWidth/2-c/2),f=parseInt(p.scrollTop+p.innerHeight/2-h/2);t.pWnd.style.width=c+"px";t.pWnd.style.height=h+"px";t.pWnd.style.overflow="hidden";jsFloatDiv.Show(t.pWnd,m,f,5,false,false);BX.bind(document,"keypress",window.MlViewItOnKeypress);t.pItemCont.style.width=a+"px";t.pItemCont.style.height=d+"px";t.pWnd.style.visibility="visible"}})},DelItem:function(e){if(!e.id)return;var t=this,i=false,l=this.arItemsCollList[e.id],o,s=l.length,n;for(o=0;o<s;o++){if(!this.GetCollection(l[o])){i=true;break}}if(!e.mode)return this.OpenConfirm({text:ML_MESS.DelItConfTxt,but1:{text:ML_MESS.DelItB1,handler:function(){t.DelItem({id:e.id,mode:"current"})}},but2:{text:ML_MESS.DelItB2,handler:function(){t.DelItem({id:e.id,mode:"all"})},disabled:i}});var a=this.SelectedColId||0;this.Request({action:"del_item",postData:{id:e.id,mode:e.mode,col_id:a},handler:function(){if(window.bx_req_res==true)t.CSDelItem({id:e.id,mode:e.mode,colId:a});else if(window.bx_req_res!==false)return false}})},SelectItem:function(e){if(e&&this.oCurItems&&this.oCurItems[e]){if(this.SelectedItemId&&this.oCurItems[this.SelectedItemId])BX.removeClass(this.oCurItems[this.SelectedItemId].pWnd,"ml-item-active");this.SelectedItemId=e;BX.addClass(this.oCurItems[e].pWnd,"ml-item-active");this.GetItemCollList(e,"FillInfoPanel",this.oCurItems[e].oItem)}else{this.SelectedItemId=false;this.FillInfoPanel(false)}},FillInfoPanel:function(e){if(!e){if(this.pButSave)this.pButSave.disabled=true;BX.addClass(this.pInfo.pWnd,"ml-no-info")}else{if(this.pButSave)this.pButSave.disabled=false;var t=this,i=this.arItemsCollList[e.id],l="",o,s=i.length,n,a;BX.removeClass(this.pInfo.pWnd,"ml-no-info");this.pInfo.name.innerHTML=BX.util.htmlspecialchars(e.name);if(e.keywords.length>0){this.pInfo.keywords.parentNode.className="";this._ChooseKeysCount(t.pInfo.keywords,t.pInfo.keywords.parentNode,e.keywords,40);this.pInfo.keywords.title=bxspcharsback(e.keywords)}else{this.pInfo.keywords.parentNode.className="ml-info-keys-h"}if(e.desc.length>0){BX.removeClass(this.pInfo.desc,"mlid-scrld");this.pInfo.desc.innerHTML=BX.util.htmlspecialchars(e.desc.replace(/\n/g,"<br />"));setTimeout(function(){var e=parseInt(t.pInfo.desc.offsetHeight);if(isNaN(e)||e>55)BX.addClass(t.pInfo.desc,"mlid-scrld")},5);this.pInfo.desc.parentNode.className=""}else{this.pInfo.desc.parentNode.className="ml-info-desc-h"}this.pInfo.collections.innerHTML="(";for(o=0;o<s;o++){a=this.GetCollection(i[o]);if(a){n=this.pInfo.collections.appendChild(BX.create("A",{props:{id:"ml_info_"+a.id,href:"javascript:void(0);",title:ML_MESS.Collection+": "+a.name,className:"ml-info-coll"},text:a.name}));n.onclick=function(){t.SelectCollection(this.id.substr("ml_info_".length),true)}}else{n=this.pInfo.collections.appendChild(BX.create("SPAN",{props:{title:ML_MESS.CollAccessDenied,className:"ml-info-coll"},text:ML_MESS.Collection+" "+i[o]}))}if(o!=s-1)this.pInfo.collections.appendChild(document.createTextNode(", "))}this.pInfo.collections.appendChild(document.createTextNode(")"));var d=ML_MESS.DateModified+": "+e.date_mod;if(e.file_size)d+="<br />"+ML_MESS.FileSize+": "+e.file_size;if(e.width&&e.height)d+="<br />"+ML_MESS.ImageSize+": "+e.width+" x "+e.height+" px";this.pInfo.details.innerHTML=d}},_ChooseKeysCount:function(e,t,i,l,o){var s=this;e.innerHTML=BX.util.htmlspecialchars(i);setTimeout(function(){var n=parseInt(t.offsetHeight),a=i.lastIndexOf(",");if(n>l&&a>0)s._ChooseKeysCount(e,t,BX.util.trim(i.substr(0,a)),l,true);else if(o)e.innerHTML+="..."},1)},GetItemCollList:function(e,t,i){if(!this.arItemsCollList[e]){var l=this;this.Request({action:"get_item_coll_list",postData:{id:e},handler:function(){if(!window._ml_items_colls)return false;l.arItemsCollList[e]=[];for(var o=0,s=window._ml_items_colls.length;o<s;o++)l.arItemsCollList[e].push(window._ml_items_colls[o]);l[t](i)}})}else{this[t](i)}},OpenEditItemDialog:function(e,t){if(!this.EditItemDialog)return this.CreateEditItemDialog(e);if(!t){this.Request({action:"bx_test",handler:function(){}});this.EditItemDialog.alreadySubmitted=false;this.EditItemDialog.alreadyLoaded=false;this.EditItemDialog.Params=e||this.EditItemDialog.Params||{};this.EditItemDialog.pIfrm.src=this.GetRequestUrl("upload_form");return}var i=this.EditItemDialog,l=i.Params.id,o=BX.GetWindowSize(),s=parseInt(o.scrollLeft+o.innerWidth/2-i.width/2),n=parseInt(o.scrollTop+o.innerHeight/2-i.height/2);i.bNew=!l;i.pWnd.style.display="block";i.Overlay.Show();this.EditItemDialog.bShow=true;this.bSubdialogOpened=true;i.arColls={};i.colLength=0;if(!i.bNew){var a=this.oCurItems[l].oItem;i.pPCFileCont.style.display=i.pLoadFDLink.style.display=i.pFDFileCont.style.display=i.pLoadPCLink.style.display="none";i.pFNFileCont.style.display="block";i.pChangeFileLink.style.display="inline";i.pChangeFileLinkBack.style.display="none";i.pFileName.innerHTML=a.file_name;this._AddItemsCollections(this.arItemsCollList[l]);i.pName.value=bxspcharsback(a.name);i.pDesc.value=bxspcharsback(a.desc);i.pKeys.value=bxspcharsback(a.keywords);if(a.width&&a.height){i.pSize.style.display="block";i.pSize.innerHTML=a.width+" x "+a.height}else{i.pSize.style.display="none"}if(a.thumb_path){i.pThumb.src=a.thumb_path;i.pNoPreview.style.display="none";if(a.width>146||a.height>136){if(a.width-a.height>0)i.pThumb.style.width="146px";else i.pThumb.style.height="136px"}else if(a.height<126){i.pThumb.style.marginTop=Math.round((126-a.height)/2)+"px"}}i.oItem=a}else{i.pFNFileCont.style.display="none";i.pChangeFileLink.style.display="none";i.pChangeFileLinkBack.style.display="none";i.pFileName.innerHTML="";i.pName.value="";i.pDesc.value="";i.pKeys.value="";i.pSize.style.display="none";if(!i.Params.parentCol&&i.Params.bGetSelCol&&this.SelectedColId&&this.oCollections[this.SelectedColId])i.Params.parentCol=this.SelectedColId;if(i.Params.parentCol>0&&this.UserCan(i.Params.parentCol,"new_item"))this._AddItemsCollections([i.Params.parentCol])}this._ReHeightEditDialog();i.pName.onchange();jsFloatDiv.Show(i.pWnd,s,n,5,false,false);BX.bind(document,"keypress",window.MlEdItemOnKeypress)},CreateEditItemDialog:function(e){var t=this,i={Params:e||false,width:420,height:350,pWnd:BX("mlsd_item"),pTitle:BX("mlsd_item_title"),pIfrm:BX("mlsd_iframe_upload"),Overlay:new BXOverlay({id:"bxml_ed_it_overlay"})};i.pIfrm.src=this.GetRequestUrl("upload_form");var t=this;if(BX.browser.IsIE())i.pIfrm.onreadystatechange=function(){t.EditItemDialogOnload()};else i.pIfrm.onload=function(){t.EditItemDialogOnload()};BX("mlsd_item_cancel").onclick=BX("mlsd_item_close").onclick=function(){t.CloseEditItemDialog()};i.pWnd.style.width=i.width+"px";i.pWnd.style.height=i.height+"px";this.EditItemDialog=i;i.Overlay.Create();BX.ZIndexManager.register(i.pWnd,{overlay:i.Overlay.pWnd});window.MlEdItemOnKeypress=function(e){if(!e)e=window.event;if(e&&e.keyCode==27)t.CloseEditItemDialog()}},EditItemDialogOnload:function(e){var t=this,i=this.EditItemDialog;i.pFrameDoc=i.pIfrm.contentDocument||i.pIfrm.contentWindow.document;i.pName=i.pFrameDoc.getElementById("mlsd_item_name");i.bFocusKeywords=false;if(!i.pName&&!this.EditItemDialog.alreadySubmitted){this.EditItemDialog.alreadySubmitted=true;return setTimeout(function(){t.CSEditItem(top.bx_req_res,top._ml_items_colls)},50)}if(this.EditItemDialog.alreadyLoaded||this.EditItemDialog.alreadySubmitted)return;this.EditItemDialog.alreadyLoaded=true;i.pDesc=i.pFrameDoc.getElementById("mlsd_item_desc");i.pKeys=i.pFrameDoc.getElementById("mlsd_item_keywords");i.pColSelect=i.pFrameDoc.getElementById("mlsd_coll_sel");i.pItCollCont=i.pColSelect.parentNode.parentNode;i.pFNFileCont=i.pFrameDoc.getElementById("mlsd_fname_cont");i.pPCFileCont=i.pFrameDoc.getElementById("mlsd_load_cont");i.pFDFileCont=i.pFrameDoc.getElementById("mlsd_select_cont");i.pLoadFile=i.pFrameDoc.getElementById("ml_load_file");i.pLoadMaxSize=i.pFrameDoc.getElementById("ml_load_max_size");i.pChangeFileLink=i.pFrameDoc.getElementById("mlsd_fname_change");i.pChangeFileLinkBack=i.pFrameDoc.getElementById("mlsd_fname_change_back");i.pLoadPCLink=i.pFrameDoc.getElementById("mlsd_select_pc");i.pLoadFDLink=i.pFrameDoc.getElementById("mlsd_select_fd");i.pItemColls=i.pFrameDoc.getElementById("mlsd_item_collections");i.pFileName=i.pFrameDoc.getElementById("ml_file_name");i.pId=i.pFrameDoc.getElementById("mlsd_item_id");i.pNoPreview=i.pFrameDoc.getElementById("mlsd_no_preview");i.pFileName=i.pFrameDoc.getElementById("ml_file_name");i.pThumb=i.pFrameDoc.getElementById("mlsd_item_thumb");i.pSize=i.pFrameDoc.getElementById("mlsd_item_size");i.pItemPath=i.pFrameDoc.getElementById("mlsd_item_path");i.pOpenFD=i.pFrameDoc.getElementById("mlsd_open_fd");i.pSourceType=i.pFrameDoc.getElementById("mlsd_source_type");i.pSaveBut=BX("mlsd_item_save");i.pForm=i.pFrameDoc.forms["ml_item_form"];i.pTbl=i.pForm.firstChild;i.pItemPath.onchange=i.pLoadFile.onchange=function(){var e=this.value;if(!e||e.length<=0)return;e=e.replace(/\\/g,"/");e=e.substr(e.lastIndexOf("/")+1);i.pName.value=e;i.pName.onchange()};i.pName.onkeydown=i.pName.onchange=function(){setTimeout(function(){var e=t.EditItemDialog,i=bxhtmlspecialchars(e.pName.value),l=e.bNew?ML_MESS.NewItem:ML_MESS.Item;e.pTitle.title=l+(i.length>0?": "+e.pName.value:"");e.pTitle.innerHTML=l+(i.length>0?": "+i:"")},20)};i.pLoadFDLink.onclick=function(){i.pPCFileCont.style.display=i.pLoadFDLink.style.display="none";i.pFDFileCont.style.display="block";i.pLoadPCLink.style.display="inline";i.pSourceType.value="FD"};i.pLoadPCLink.onclick=function(){i.pPCFileCont.style.display="block";i.pLoadFDLink.style.display="inline";i.pFDFileCont.style.display=i.pLoadPCLink.style.display="none";i.pSourceType.value="PC"};i.pChangeFileLink.onclick=function(){i.pFNFileCont.style.display="none";i.pChangeFileLink.style.display="none";i.pChangeFileLinkBack.style.display="inline";i.pLoadPCLink.onclick()};i.pChangeFileLinkBack.onclick=function(){i.pPCFileCont.style.display=i.pLoadFDLink.style.display=i.pFDFileCont.style.display=i.pLoadPCLink.style.display="none";i.pFNFileCont.style.display="block";i.pChangeFileLink.style.display="inline";i.pChangeFileLinkBack.style.display="none";i.pSourceType.value="N"};i.pColSelect.onchange=function(){t._AddCollToItem(this.value);this.value=0};i.pSaveBut.onclick=function(){if(t.EditItemDialogOnsubmit()){i.pForm.submit();t.CloseEditItemDialog()}};i.pOpenFD.onclick=window.mlOpenFileDialog;window.mlOnFileDialogSave=function(e,t,l){var o=(t=="/"?"":t)+"/"+e;i.pItemPath.value=o;i.pItemPath.focus();i.pItemPath.select();i.pItemPath.onchange();BX.fireEvent(i.pItemPath,"change")};i.pKeys.onchange=i.pKeys.onblur=function(){t.EditItemDialog.bFocusKeywords=true};this._ReqBuildCollSelect(i.pColSelect,this.arCollectionsTree,0,true);this.OpenEditItemDialog(false,true)},EditItemDialogOnsubmit:function(e){var t=this.EditItemDialog,i,l=this.EditItemDialog.arColls,o="";for(i in l)if(l[i]&&typeof l[i]=="object"&&l[i].pWnd)o+=(o==""?"":",")+i;var s=t.pSourceType.value=="PC"?t.pLoadFile.value:t.pItemPath.value;if((t.bNew||s!=="")&&!this.CheckFileExt(s)){alert(ML_MESS.ItemExtError);return}if((t.bNew||s!=="")&&!this.CheckFileExt(s,this.curType.arExt)&&!confirm(ML_MESS.CheckExtTypeConf))return false;if(t.bNew){var n=true;if(s=="")alert(ML_MESS.ItSourceError);else if(!this.CheckFileExt(s))alert(ML_MESS.ItemExtError);else n=false;if(n){if(t.pSourceType.value=="PC"){t.pLoadPCLink.onclick();t.pLoadFile.focus()}else{t.pLoadFDLink.onclick();t.pItemPath.focus()}return false}}if(t.pName.value==""){alert(ML_MESS.ItNameError);t.pName.focus();return false}if(o==""){alert(ML_MESS.ItCollsError);t.pColSelect.focus();return false}if(!this.EditItemDialog.bNew)this.EditItemDialog.pId.value=this.EditItemDialog.oItem.id;this.EditItemDialog.pItemColls.value=o;return true},CloseEditItemDialog:function(){this.EditItemDialog.bShow=false;this.EditItemDialog.Params=false;this.bSubdialogOpened=false;this.EditItemDialog.pWnd.style.display="none";jsFloatDiv.Close(this.EditItemDialog.pWnd);this.EditItemDialog.Overlay.Hide();BX.unbind(document,"keypress",window.MlEdItemOnKeypress)},_AddItemsCollections:function(e){var t,i=e.length;for(t=0;t<i;t++)this._AddCollToItem(e[t],false)},_AddCollToItem:function(e,t){if(this.EditItemDialog.arColls[e])return;if(this.EditItemDialog.bNew&&!this.UserCan(parseInt(e),"new_item")||!this.EditItemDialog.bNew&&!this.UserCan(parseInt(e),"edit_item"))return alert(ML_MESS.CollAccessDenied4);var i=this.GetCollection(e);if(!i)i={};var l,o,s=this,n=this.EditItemDialog.pColSelect,a=BX.create("DIV",{props:{className:"mlsd-ch-col",title:i.name}},this.EditItemDialog.pFrameDoc),d=a.appendChild(BX.create("SPAN",{text:i.name},this.EditItemDialog.pFrameDoc)),r=a.appendChild(BX.create("IMG",{props:{src:"/bitrix/images/1.gif",className:"ml-col-del",title:ML_MESS.DelColFromItem,id:"mlsd_it_"+e}},this.EditItemDialog.pFrameDoc));if(i&&i.name){if(t!==false&&(this.EditItemDialog.bNew&&!this.UserCan(i,"new_item")||!this.EditItemDialog.bNew&&!this.UserCan(i,"edit_item")))return alert(ML_MESS.CollAccessDenied2);if(i&&i.keywords&&this.EditItemDialog.bNew&&!this.EditItemDialog.bFocusKeywords)this.AppendKeywords(this.EditItemDialog.pKeys,i.keywords);this.EditItemDialog.pItCollCont.onmouseover=function(e){};this.EditItemDialog.pItCollCont.onmouseout=function(e){};a.onmouseover=function(){BX.addClass(this,"col-over")};a.onmouseout=function(){BX.removeClass(this,"col-over")};r.onclick=function(e){var t=this.id.substr("mlsd_it_".length);s.EditItemDialog.pItCollCont.removeChild(s.EditItemDialog.arColls[t].pWnd);s._SelectOptionInColList(s.EditItemDialog.pColSelect,t,false);s.EditItemDialog.arColls[t]=null;s.EditItemDialog.colLength--;s._ReHeightEditDialog()}}else{a.title=ML_MESS.CollAccessDenied;d.innerHTML=ML_MESS.Collection+" "+e}this.EditItemDialog.colLength++;this.EditItemDialog.pItCollCont.insertBefore(a,n.parentNode);s._SelectOptionInColList(n,e);if(t!==false)this._ReHeightEditDialog();this.EditItemDialog.arColls[e]={pWnd:a}},_SelectOptionInColList:function(e,t,i){for(var l=0,o=e.options.length;l<o;l++){if(e.options[l].value==t){e.options[l].className=i!==false?"opt-checked":"";e.options[l].title=i!==false?ML_MESS.CheckedColTitle:"";break}}},_ReHeightEditDialog:function(){var e=Math.ceil((this.EditItemDialog.colLength+2)/4);if(e<2)e=2;var t=(e-2)*28;this.EditItemDialog.pItCollCont.style.height=e*28+"px";this.EditItemDialog.pIfrm.style.height=275+t+"px";this.EditItemDialog.pTbl.style.height=265+t+"px";this.EditItemDialog.pWnd.style.height=350+t+"px";jsFloatDiv.AdjustShadow(this.EditItemDialog.pWnd)},GetRequestUrl:function(e){return"/bitrix/admin/fileman_medialib.php?sessid="+this.sessid+"&lang="+this.oConfig.lang+(e?"&action="+e:"")},CheckReqLostSessid:function(e){var t="BX_ML_DUBLICATE_ACTION_REQUEST",i=e.indexOf(t);if(i==-1)return true;this.sessid=e.substring(i+t.length,e.lastIndexOf("--\x3e"));return this.sessid},Resize:function(e,t){if(e<565)e=565;if(t<400)t=400;this.width=e;this.height=t;this.pWnd.style.width=e+"px";this.pWnd.style.height=t+"px";jsFloatDiv.AdjustShadow(this.pWnd);var i=t-95;contW=e,rW=contW-220;this.pHeaderCont.style.width=e-10+"px";this.pFrameTbl.style.height=t+"px";this.pLeftCont.style.height=i+"px";this.pRightCont.style.height=i+"px";this.pRightCont.style.width=rW+3+"px";this.pCollCont.style.height=i-(this.bTypes?39:0)+"px";this.pListCont.style.height=i-110+"px";this.pInfo.desc.style.width=Math.round(rW/2)-10+"px";this.pListCont.style.width=rW+"px";this.pInfo.pWnd.style.width=rW-10+"px";this.pButCont.style.width=contW+"px";this.pResizer.style.left=e-20+"px";this.pResizer.style.top=t-20+"px"},ResizerMouseDown:function(){var e=this;this.oPos={top:parseInt(this.pWnd.style.top,10),left:parseInt(this.pWnd.style.left,10)};window["MLResizerMouseUp"]=function(){e.ResizerMouseUp()};window["MLResizerMouseMove"]=function(t){e.ResizerMouseMove(t)};BX.bind(document,"mouseup",window["MLResizerMouseUp"]);BX.bind(document,"mousemove",window["MLResizerMouseMove"])},ResizerMouseUp:function(){this.SaveSettings();BX.unbind(document,"mouseup",window["MLResizerMouseUp"]);BX.unbind(document,"mousemove",window["MLResizerMouseMove"]);this.SelectItem(this.SelectedItemId)},ResizerMouseMove:function(e){var t=BX.GetWindowSize(),i=e.clientX+t.scrollLeft,l=e.clientY+t.scrollTop;w=i-this.oPos.left,h=l-this.oPos.top;this.Resize(w,h)},Request:function(e){e.url=this.GetRequestUrl(e.action);if(!e.postData)e.postData={};var t=this,i=0;var l=function(l){var o=function(){t.CloseWaitWindow();if(l.indexOf("BX_ML_LOAD_OK")==-1)return alert(ML_MESS.AccessDenied);var s=t.CheckReqLostSessid(l);if(s!==true){if(e.bRequestReply)alert(ML_MESS.SessExpired);else{e.bRequestReply=true;setTimeout(function(){t.Request(e)},50)}return}var n=e.handler(l);if(n===false&&++i<20)setTimeout(o,3)};setTimeout(o,10)};window.bx_req_res=false;this.ShowWaitWindow();jsAjaxUtil.PostData(e.url,e.postData,l)},ShowWaitWindow:function(){if(window.ShowWaitWindow)ShowWaitWindow()},CloseWaitWindow:function(){if(window.CloseWaitWindow)CloseWaitWindow()},OpenConfirm:function(e){var t=e.width||560,i=e.height||100,l=e.zIndex||this.zIndex+100;_this=this;if(!this.Confirm){var o={pWnd:BX("ml_colfirm_dialog"),pText:BX("ml_confd_text"),but1:BX("ml_confd_b1"),but2:BX("ml_confd_b2"),butCancel:BX("ml_confd_cancel"),Overlay:new BXOverlay({id:"bxml_conf_overlay"})};o.butCancel.onclick=function(){_this.CloseConfirm()};o.Overlay.Create();BX.ZIndexManager.register(o.pWnd,{overlay:o.Overlay.pWnd})}else{var o=this.Confirm}o.pWnd.style.width=t+"px";o.pWnd.style.height=i+"px";o.pWnd.style.display="block";this.bSubdialogOpened=true;var s=BX.GetWindowSize(),n=parseInt(s.scrollLeft+s.innerWidth/2-t/2),a=parseInt(s.scrollTop+s.innerHeight/2-i/2);jsFloatDiv.Show(o.pWnd,n,a,0,false,false);o.Overlay.Show({clickCallback:{func:this.CloseConfirm,obj:this}});o.but1.value=e.but1.text;o.but1.onclick=function(t){e.but1.handler(t);_this.CloseConfirm()};o.but1.disabled=!!e.but1.disabled;o.but1.focus();if(e.but2){o.but2.style.display="inline";o.but2.value=e.but2.text;o.but2.disabled=!!e.but2.disabled;o.but2.onclick=function(t){e.but2.handler(t);_this.CloseConfirm()}}else{o.but2.style.display="none"}o.pText.innerHTML=e.text;this.Confirm=o;window.MlConfDialofOnKeypress=function(e){if(!e)e=window.event;if(e&&e.keyCode==27)_this.CloseConfirm()};BX.bind(document,"keypress",window.MlConfDialofOnKeypress)},CloseConfirm:function(){this.Confirm.pWnd.style.display="none";jsFloatDiv.Close(this.Confirm.pWnd);this.Confirm.Overlay.Hide();this.bSubdialogOpened=false;BX.unbind(document,"keypress",window.MlConfDialofOnKeypress)},SaveSettings:function(){if(this.width&&this.height){this.userSettings.width=this.width;this.userSettings.height=this.height}this.Request({action:"save_settings",postData:this.userSettings,handler:function(){}})},CSDelCollection:function(e,t,i){var l=this.oCollections[e];if(l){var o=this.GetCollection(e);if(t!==false&&typeof o=="object"&&o.parent>0)this._IncreaseCollChild(parseInt(o.parent),-1);if(this.SelectedColId&&this.SelectedColId==e)this.DeSelectCollection();this.arCollections=BX.util.deleteFromArray(this.arCollections,l.ind);for(col_id in this.oCollections){if(this.oCollections[col_id]&&this.oCollections[col_id].ind>l.ind)this.oCollections[col_id].ind--}var s=l.pChildCont.parentNode;if(s){s.removeChild(l.pChildCont);s.removeChild(l.pTitle)}if(i===undefined)i=true;if(s.childNodes.length>0){for(var n=0,a=s.childNodes.length;n<a;n++){if(s.childNodes[n]&&s.childNodes[n].className&&s.childNodes[n].className.indexOf("ml-no-colls")==-1){i=false;break}}}else i=false;if(i){BX.addClass(this.pLeftCont,"ml-no-colls-sect");this.pAddNewItem.style.display="none"}this.oCollections[e]=null;if(t){for(var n=0,a=t.length;n<a;n++)this.CSDelCollection(t[n],false,i)}if(t!==false)this.ReNewCollectionTree()}},CSDelItem:function(e){var t=e.id,i=this.oCurItems[t],l=[];if(!i)return;if(this.ViewItDialog&&this.ViewItDialog.bOpened)this.CloseViewItDialog();if(e.mode=="current"){l.push(parseInt(this.SelectedColId));this.arItemsCollList[t]=false}else{if(!this.arItemsCollList[t])return this.GetItemCollList(t,"CSDelItem",e);l=this.arItemsCollList[t]}var o,s=l.length,n,a,d,r;for(o=0;o<s;o++){if(MLItems[l[o]]){n=MLItems[l[o]].length;for(a=0;a<n;a++){d=MLItems[l[o]][a];if(d.id==t){MLItems[l[o]]=BX.util.deleteFromArray(MLItems[l[o]],a);break}}}}this.currentIdShowed=0;r=this.SelectedColId;if(r){this.SelectedColId=0;this.SelectCollection(r)}this.SelectItem()},CSEditItem:function(e,t){if(!e){if(parseInt(this.EditItemDialog.pLoadFile.files[0].size)>parseInt(this.EditItemDialog.pLoadMaxSize.value)){var i=parseInt(this.EditItemDialog.pLoadMaxSize.value)/(1024*1024);return alert(ML_MESS.ItFileSizeError.replace("#FILESIZE#",i))}}if(!e||typeof t!="object")return alert(ML_MESS.EditItemError);var l,o=t.length,s=e.id,n,a=this.arItemsCollList[s]||[],d=a.length,r={};if(a.length>0){n=this.FindItem(a[0],s);if(n!==false)e=this._MergeItemInfo(MLItems[a[0]][n],e)}for(l=0;l<o;l++){if(MLItems[t[l]]){n=this.FindItem(t[l],s);if(n===false)MLItems[t[l]].push(e);else MLItems[t[l]][n]=e;r[t[l]]=true}}for(l=0;l<d;l++){if(!r[a[l]]){n=this.FindItem(a[l],s);if(n!==false){MLItems[a[l]]=BX.util.deleteFromArray(MLItems[a[l]],n);this.ShowItems(a[l])}}}this.currentIdShowed=0;this.arItemsCollList[s]=t;var h=this.SelectedColId;if(h){this.SelectedColId=0;this.SelectCollection(h)}this.SelectItem(s)},_MergeItemInfo:function(e,t){if(typeof e=="object"&&typeof t=="object"){for(var i in t){if(t[i]&&(t[i].length>0||t[i]>0))e[i]=t[i]}}return e},FindItem:function(e,t){if(MLItems[e]&&typeof MLItems[e]=="object"&&MLItems[e].length>0){var i,l=MLItems[e].length;for(i=0;i<l;i++){el=MLItems[e][i];if(el&&el.id==t)return i}}return false},CheckFileExt:function(e,t){e=e.substr(e.lastIndexOf(".")+1);e=e.toLowerCase();if(!t)t=this.arExt;for(var i=0,l=t.length;i<l;i++)if(t[i]==e)return true;return false},AppendKeywords:function(e,t){if(!e||!t)return;var i=[],l=e.value.split(",").concat(t.split(",")),o,s,n=l.length;for(s=0;s<n;s++){o=BX.util.trim(l[s]);if(o&&!BX.util.in_array(o,i))i.push(o)}e.value=i.join(", ")},InitTypeSelector:function(){this.bTypes=this.Types.length>1;if(this.bTypes){this.pTypeCont=BX("ml_type_cont");this.pTypeCont.style.display="block";this.oTypeSelector=new BXMLTypeSelector({oML:this,Types:this.Types,oCallback:{obj:this,func:this.TypeOnChange}});this.pTypeCont.appendChild(this.oTypeSelector.pWnd);this.oTypeSelector.SetType(0,false);this.curType=this.Types[0]}else{this.curType=this.Types[0]}},TypeOnChange:function(e){this.curType=this.Types[e.typeInd];var t,i=this.pCollCont.childNodes.length,l;for(t=i-1;t>=0;t--){l=this.pCollCont.childNodes[t];if(l.className.indexOf("ml-no-colls")==-1)this.pCollCont.removeChild(l)}this.BuildCollections();this.BuildCrumbs([]);this.DisplayItems()},CheckMLType:function(e){e=parseInt(e);if(!this.bTypes||e==this.curType.id)return true;if((!this.curType||this.curType.code=="image"&&this.curType.system)&&(!e||e==this.curType.id))return true;return false}};function BXMLSearch(e){this.oML=e;this.Init()}BXMLSearch.prototype={Init:function(){var e=this;this.bShowed=false;this.pInput=BX("medialib_search");this.pInput.onfocus=function(e){if(this.value==ML_MESS.SearchDef){this.value="";this.className="ml-search"}};this.pInput.onblur=function(e){if(this.value==ML_MESS.SearchDef||this.value==""){this.value=ML_MESS.SearchDef;this.className="ml-search ml-search-empty"}};this.pInput.onkeydown=function(t){if(!t)t=window.event;if(t.keyCode==13){if(this.value.length>0)e.Search(this.value);return BX.PreventDefault(t)}}},Search:function(e){var t=this;window.MLSearchResult=false;this.oML.Request({action:"search",postData:{q:e,types:t.oML.requestTypes},handler:function(){if(window.MLSearchResult)t.DisplayResult(window.MLSearchResult,e)}})},DisplayResult:function(e,t){this.bShowed=true;this.Query=t;this.oML.DeSelectCollection();this.oML.pBread.appendChild(BX.create("SPAN",{props:{className:"ml-search-title"},text:ML_MESS.SearchResultEx.replace("#SEARCH_QUERY#",t)}));while(this.oML.pListCont.childNodes[1])this.oML.pListCont.removeChild(this.oML.pListCont.lastChild);this.oML.oCurItems={};this.oML.pListCont.firstChild.style.display="none";var i,l=e.length;if(l>0){for(i=0;i<l;i++)this.oML.DisplayItem(e[i],e[i].perm,true)}else{this.oML.pListCont.appendChild(BX.create("DIV",{props:{className:"ml-search-no-result"},text:ML_MESS.NoResult}))}}};
//# sourceMappingURL=core.map.js